package com.stormragetech.arthas.process.proxy;

import com.stormragetech.arthas.common.exception.ArthasException;
import com.stormragetech.arthas.common.util.Assert;
import com.stormragetech.arthas.process.factory.ActionWrapper;
import com.stormragetech.arthas.process.invocation.ActionInvoke;
import lombok.extern.log4j.Log4j2;

import java.lang.reflect.Method;

/**
 * description: factory proxy implement
 *
 * @author: Xue Bin
 * @version: 1.0.0-SNAPSHOT
 */
@Log4j2
public class FactoryProxy<T> implements Proxy {

    private ActionWrapper<T> wrapper;
    private ActionInvoke invoke;

    public FactoryProxy(ActionWrapper<T> wrapper) {
        Assert.notNull(wrapper, "ActionWrapper cannot be null !!!");
        this.wrapper = wrapper;
    }

    @Override
    public T getAction() {
        return wrapper.getAction();
    }

    @Override
    public Method getMethod() {
        return wrapper.getMethod();
    }

    @Override
    public void setInvoke(ActionInvoke invoke) {
        this.invoke = invoke;
    }

    @Override
    public String execute() throws ArthasException {
        return invoke.invoke();
    }
}
